﻿package com.example.dzj.lab1;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    private Button button;
    private boolean change=false;
    private Intent intent;
    private int i;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button=(Button)findViewById(R.id.bt);
        button.setOnClickListener(bt);
    }
    View.OnClickListener bt=new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(!change){
                change=true;
                intent=new Intent(MainActivity.this,MyService.class);
                startService(intent);
                button.setText("停止Service");
            }else{
                change=false;
                stopService(intent);
                button.setText("启动Service");
            }
        }
    };
}
